/**

 @Name：layuiAdmin 主页控制台
 @Author：贤心
 @Site：http://www.layui.com/admin/
 @License：GPL-2

 */
var cyywqs;
var ywlxfb;
var lastsevenday;
var lastsevenbus;
$(function () {
    getEchartsData()
})

layui.define(function (exports) {

    /*
      下面通过 layui.use 分段加载不同的模块，实现不同区域的同时渲染，从而保证视图的快速呈现
    */


    //区块轮播切换
    layui.use(['admin', 'carousel'], function () {
        var $ = layui.$
            , admin = layui.admin
            , carousel = layui.carousel
            , element = layui.element
            , device = layui.device();

        //轮播切换
        $('.layadmin-carousel').each(function () {
            var othis = $(this);
            carousel.render({
                elem: this
                , width: '100%'
                , arrow: 'none'
                , interval: othis.data('interval')
                , autoplay: othis.data('autoplay') === true
                , trigger: (device.ios || device.android) ? 'click' : 'hover'
                , anim: othis.data('anim')
            });
        });

        element.render('progress');

    });

    //数据概览
    layui.use(['carousel', 'echarts'], function () {
        var $ = layui.$
            , carousel = layui.carousel
            , echarts = layui.echarts;

        var echartsApp = [], options = [
            //今日流量趋势
            {
                title: {
                    text: '近三天视频数据上传量',
                    x: 'center',
                    textStyle: {
                        fontSize: 14
                    }
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['', '']
                },
                xAxis: [{
                    type: 'category',
                    boundaryGap: false,
                    data: ['08:00', '08:30', '09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00']
                }],
                yAxis: [{
                    type: 'value'
                }],
                series: [{
                    name: '查验量',
                    type: 'line',
                    smooth: true,
                    itemStyle: {normal: {areaStyle: {type: 'default'}}},
                    data: cyywqs
                }]
            },

            //访客浏览器分布
            {
                title: {
                    text: '近七天业务类型分布情况',
                    x: 'center',
                    textStyle: {
                        fontSize: 14
                    }
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    x: 'left',
                    data: ['大型汽车', '小型汽车', '警用汽车', '普通摩托车', '大型新能源', '小型新能源', '其他']
                },
                series: [{
                    name: '号牌种类',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '50%'],
                    data: ywlxfb
                }]
            },
            {
                title: {
                    text: '最近一周业务量统计',
                    x: 'center',
                    textStyle: {
                        fontSize: 14
                    }
                },
                tooltip: { //提示框
                    trigger: 'axis',
                    formatter: "{b}<br>业务量：{c}"
                },
                xAxis: [{ //X轴
                    type: 'category',
                    data: lastsevenday
                }],
                yAxis: [{  //Y轴
                    type: 'value'
                }],
                series: [{ //内容
                    type: 'line',
                    data: lastsevenbus,
                }]
            }
        ]
            , elemDataView = $('#LAY-index-dataview').children('div')
            , renderDataView = function (index) {
            echartsApp[index] = echarts.init(elemDataView[index], layui.echartsTheme);
            echartsApp[index].setOption(options[index]);
            window.onresize = echartsApp[index].resize;
        };


        //没找到DOM，终止执行
        if (!elemDataView[0]) return;


        renderDataView(0);

        //监听数据概览轮播
        var carouselIndex = 0;
        carousel.on('change(LAY-index-dataview)', function (obj) {
            renderDataView(carouselIndex = obj.index);
        });

        //监听侧边伸缩
        layui.admin.on('side', function () {
            setTimeout(function () {
                renderDataView(carouselIndex);
            }, 300);
        });

        //监听路由
        layui.admin.on('hash(tab)', function () {
            layui.router().path.join('') || renderDataView(carouselIndex);
        });
    });

    //最新订单
    layui.use('table', function () {
        var $ = layui.$
            , table = layui.table;

        //今日热搜
        // table.render({
        //     elem: '#LAY-index-topSearch'
        //     , url: "/HomeData/getCyqTopData"
        //     , method: 'POST'
        //     , page: true
        //     , cols: [[
        //         {type: 'numbers', fixed: 'left'}
        //         , {
        //             field: 'name',
        //             title: '查验区名称',
        //             minWidth: 300
        //         }
        //         , {field: 'jrywl', title: '今日业务量', minWidth: 120, sort: true}
        //         , {field: 'ywzl', title: '业务总量', sort: true}
        //     ]]
        //     , skin: 'line'
        // });

        //今日热贴
        // table.render({
        //     elem: '#LAY-index-topCard'
        //     , url: "/HomeData/getCyyTopData"
        //     , page: true
        //     , method: 'POST'
        //     , cellMinWidth: 120
        //     , cols: [[
        //         {type: 'numbers', fixed: 'left'}
        //         , {
        //             field: 'cyyxm',
        //             title: '查验员姓名',
        //             width: 120,
        //         }
        //         , {field: 'cyqmc', title: '所属查验区'}
        //         , {field: 'count', title: '近七天查验量'}
        //     ]]
        //     , skin: 'line'
        // });
    });

    exports('console', {})
});

function getEchartsData() {
    // $.ajax({
    //     type: "POST",
    //     async: false,
    //     cache: false,
    //     data: {},
    //     url: ctxPath + "/getEchartsData",
    //     success: function (data) {
    //         if (data.code == 1) {
    //             cyywqs = data.cyywqs;
    //             ywlxfb = data.ywlxfb;
    //             lastsevenday = data.lastsevenday;
    //             lastsevenbus = data.lastsevenbus;
    //         } else {
    //             layer.alert(data.message)
    //         }
    //     },
    //     error: function () {
    //         //alert("下拉框ajax异常！")
    //     }
    // });
}